package com.future.common.utils;

import java.util.List;
import java.util.UUID;

import com.corundumstudio.socketio.SocketIOServer;
import com.future.common.global.PlatFormContext;

public class SocketIoUtil {
	private static SocketIOServer server = PlatFormContext.getServer();

	/**
	 * 给某一个客户端发送数据
	 * 
	 * @param sessionId
	 * @param eventName
	 * @param message
	 */
	public static void sendMessage(List<String> sessionIdList, String eventName, Object message) {
		if (server == null) {
			throw new RuntimeException("请先启动socket服务");
		}
		for (int i = 0; i < sessionIdList.size(); i++) {
			server.getClient(UUID.fromString(sessionIdList.get(i))).sendEvent(eventName, message);
		}
	}
	/**
	 * 广播消息
	 * @param eventName
	 * @param message
	 */
	public static void sendBroadcastMessage(String eventName, Object message) {
		if (server == null) {
			throw new RuntimeException("请先启动socket服务");
		}
		server.getBroadcastOperations().sendEvent(eventName, message);
	}

}
